package com.robotic.route.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.robotic.common.utils.DateUtils;
import com.robotic.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.robotic.route.mapper.InspectionRecordMapper;
import com.robotic.route.domain.InspectionRecord;
import com.robotic.route.service.IInspectionRecordService;

/**
 * 巡检记录管理Service业务层处理
 *
 * @author tian
 * @date 2025-09-15
 */
@Service
public class InspectionRecordServiceImpl extends ServiceImpl<InspectionRecordMapper, InspectionRecord> implements IInspectionRecordService
{
    @Autowired
    private InspectionRecordMapper inspectionRecordMapper;

    /**
     * 查询巡检记录管理
     *
     * @param id 巡检记录管理主键
     * @return 巡检记录管理
     */
    @Override
    public InspectionRecord selectInspectionRecordById(Long id)
    {
        return inspectionRecordMapper.selectInspectionRecordById(id);
    }

    /**
     * 查询巡检记录管理列表
     *
     * @param inspectionRecord 巡检记录管理
     * @return 巡检记录管理
     */
    @Override
    public List<InspectionRecord> selectInspectionRecordList(InspectionRecord inspectionRecord)
    {
        LambdaUpdateWrapper<InspectionRecord> wrapper = Wrappers.lambdaUpdate(InspectionRecord.class);
        wrapper.ge(inspectionRecord.getStartTime() != null, InspectionRecord::getStartTime, inspectionRecord.getStartTime());
        wrapper.le(inspectionRecord.getEndTime() != null, InspectionRecord::getEndTime, inspectionRecord.getEndTime());
        wrapper.eq(StringUtils.isNotEmpty(inspectionRecord.getTaskType()), InspectionRecord::getTaskType, inspectionRecord.getTaskType());
        wrapper.eq(StringUtils.isNotEmpty(inspectionRecord.getRegion()), InspectionRecord::getRegion, inspectionRecord.getRegion());
        wrapper.eq(StringUtils.isNotEmpty(inspectionRecord.getStatus()), InspectionRecord::getStatus, inspectionRecord.getStatus());
        wrapper.orderByDesc(InspectionRecord::getStartTime);
        return inspectionRecordMapper.selectList(wrapper);
    }

    /**
     * 新增巡检记录管理
     *
     * @param inspectionRecord 巡检记录管理
     * @return 结果
     */
    @Override
    public int insertInspectionRecord(InspectionRecord inspectionRecord)
    {
        inspectionRecord.setCreateTime(DateUtils.getNowDate());
        int insert = inspectionRecordMapper.insert(inspectionRecord);
        Long recordId = inspectionRecord.getId();
        return insert;
    }

    /**
     * 修改巡检记录管理
     *
     * @param inspectionRecord 巡检记录管理
     * @return 结果
     */
    @Override
    public int updateInspectionRecord(InspectionRecord inspectionRecord)
    {
        inspectionRecord.setUpdateTime(DateUtils.getNowDate());
        return inspectionRecordMapper.updateInspectionRecord(inspectionRecord);
    }

    /**
     * 批量删除巡检记录管理
     *
     * @param ids 需要删除的巡检记录管理主键
     * @return 结果
     */
    @Override
    public int deleteInspectionRecordByIds(Long[] ids)
    {
        return inspectionRecordMapper.deleteInspectionRecordByIds(ids);
    }

    /**
     * 删除巡检记录管理信息
     *
     * @param id 巡检记录管理主键
     * @return 结果
     */
    @Override
    public int deleteInspectionRecordById(Long id)
    {
        return inspectionRecordMapper.deleteInspectionRecordById(id);
    }
}
